package com.szt.school.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

//@Configuration
//@PropertySource("classpath:jdbc.properties")
//@EnableConfigurationProperties({JdbcProperties.class})
public class JdbcConfig {
    //@Bean
    //@ConfigurationProperties(prefix = "jdbc")
    //public DataSource getDataSource(){
    //   return new DruidDataSource();
    //}

/*    @Value("${jdbc.driverClassName}")
    private String driver;
    @Value("${jdbc.url}")
    private String  url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Bean
    public DataSource getDataSource(){

        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }*/
    //使配置类和属性的读取类分开
/*    @Bean
    public DataSource dataSource(JdbcProperties jdbc){
        DruidDataSource dataSource = new
                DruidDataSource();
        dataSource.setDriverClassName(jdbc.getDriverClassName());
        dataSource.setUrl(jdbc.getUrl());
        dataSource.setUsername(jdbc.getUsername());
        dataSource.setPassword(jdbc.getPassword());
        return dataSource;
    }*/

}
